﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


namespace lcmyjobs.Web.Controls
{
    /// <summary>
    /// 获取职位信息，包括急聘职位(isfrist=1)、校园招聘职位(workerclass=2)、最新职位(bcount=0即访问次数为0的职位)的信息
    /// </summary>
    public partial class GridJobs : System.Web.UI.UserControl
    {
        private string _condition;
        private string _value;
        private bool _isShowAspNetPager;
        private string[] _cells;
       

        /// <summary>
        /// gridview显示的列名称
        /// </summary>
        public string[] cells
        {
            get { return _cells; }
            set { _cells = value; }
        }
        
        /// <summary>
        /// 是否显示分页控件
        /// </summary>
        public bool isShowAspNetPager
        {
            get { return _isShowAspNetPager; }
            set { _isShowAspNetPager = value; }
        }
        /// <summary>
        /// 值
        /// </summary>
        public string value
        {
            get { return _value; }
            set { _value = value; }
        }
        /// <summary>
        /// 条件，包括急聘职位(isfrist=1)、校园招聘职位(workerclass=2)、最新职位(bcount=0即访问次数为0的职位)
        /// </summary>
        public string condition
        {
            get { return _condition; }
            set { _condition = value; }
        }
        

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Application["webid"] != null)
                {
                    Bind(Convert.ToInt32(Application["webid"]));
                }
               
            }
        }

        private void Bind(int atid)
        {
            lcmyjobs.BLL.enterprise_releasejob rj = new BLL.enterprise_releasejob();
            //int count = 0;
            //DataSet ds = rj.GetReleaseJobsByCondition(condition, atid, value, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out count);


            int c_isfrist = 0;
            int c_reward = 0;
            int c_vip = 0;
            int c_hunter = 0;
            int c_newjob = 0;
            int c_workerclass = 0;


            DataSet ds = new lcmyjobs.BLL.enterprise_releasejob().GetJobsInfo(false, false, false, false, false, true,
                                                atid, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize,
                                                out c_isfrist, out c_reward, out c_hunter, out c_vip, out c_newjob, out c_workerclass);

            List<int> idl = new List<int>();


            if (this.cells.Length <= this.GridView1.Columns.Count)
            {
                for (int i = 0; i < this.cells.Length; i++)
                {
                    for (int j = 0; j < this.GridView1.Columns.Count; j++)
                    {
                        if (this.GridView1.Columns[j].HeaderText == cells[i])
                        {
                            idl.Add(j);
                        }

                    }

                }
            }

            for (int i = 0; i < idl.Count; i++)
            {
                this.GridView1.Columns[idl[i]].Visible = true;
            }

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();

            this.AspNetPager1.RecordCount = c_workerclass;

            this.AspNetPager1.Visible = isShowAspNetPager;
            
        
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {

            if (Application["webid"] != null)
            {
                this.cells = new string[7] { "招聘职位", "招聘单位", "工作地区", "刷新时间", "专业要求", "最低学历", "月薪待遇" };
                this.isShowAspNetPager = true;
                this.condition = "workerclass";
                this.value = "2";
                Bind(Convert.ToInt32(Application["webid"]));
            }

             
        }

     
       

    }
}